package sets.set.hashSet;

public class HashDemo {
    public static void main(String[] args) {
        Integer[] nums = {94481199,44646444,89774541,94841646};
        showBinary(nums);
        show1(nums);
        System.out.println("-----------------");
        show2(nums);
    }



    //打印二进制，发现后边的数字差别不大，这样索引位置很大可能相同，故向右移动16位
    private static void showBinary(Integer[] nums) {
        String[] str = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            str[i] = Integer.toBinaryString(nums[i]);
            System.out.println(str[i]);
        }
    }
    //不进行哈希扰动，不进行二次哈希所计算出来的索引
    public static void show1(Integer[] nums) {
        for(Integer num : nums) {
            int hash = num.hashCode()%16;
            System.out.println(hash);
        }
    }
    //进行哈希扰动，二次哈希后的索引位置
    private static void show2(Integer[] nums) {
        for (Integer num:nums){
            int hash = num.hashCode();
            hash = (hash^(hash>>>16))%16;
            System.out.println(hash);
        }
    }
}
